package com.xb.cloud.gateway.core;

import com.xb.cloud.gateway.client.RtnCodes;
import com.xb.cloud.gateway.client.RtnInfo;

/**
 * 
 * @ClassName:  RtnInfoCreater   
 * @Description:TODO
 * @author: 鲜备科技
 * @date:   2017年12月18日 下午6:10:36   
 *     
 * @Copyright: 2017 www.xianbeitech.com Inc. All rights reserved. 
 *
 */
public class RtnInfoCreater
{


    public static RtnInfo RightWlRtnInfo() {
        return new RtnInfo(RtnCodes.SUCCESS, "", "");
    }
         

    /**
     * 构建上下文异常
     * @param rtn_ext
     * @return
     */
    public static RtnInfo BuildContextErrorAdapter(String rtn_ext) {
        return new RtnInfo(RtnCodes.CONTEXT_BUILD_ERROR, "fail to build context", rtn_ext);
    }
     
    
    /**
     * 找不到合适的适配器
     * @param rtn_ext
     * @return
     */
    public static RtnInfo CannotFindAdapter(String rtn_ext) {
        return new RtnInfo(RtnCodes.INVALID_URL, "can not find adapter", rtn_ext);
    }

    /**
     * 触发适配器异常
     * @param rtn_ext
     * @return
     */
    public static RtnInfo InvokeAdapterError(String rtn_ext) {
        return new RtnInfo(RtnCodes.ADAPTER_EXCEPTION, "服务器正在打盹， 请重试敲醒它", rtn_ext);
    }
    
    /**
     * 触发适配器超时
     * @param rtn_ext
     * @return
     */
    public static RtnInfo InvokeAdapterTimeout(String rtn_ext) {
        return new RtnInfo(RtnCodes.ADAPTER_TIMEOUT, "Adapter invoke timeout", rtn_ext);
    }
    
    /**
     * 服务因降级被略过
     * @param rtn_ext
     * @return
     */
    public static  RtnInfo IgnoreServiceError(String rtn_ext){
        return new RtnInfo(RtnCodes.SERVICE_REFEREE_IGNORE, "Request was ignored", rtn_ext);
    }
     
    /**
     * 调用handler异常
     * @param rtn_ext
     * @return
     */
    public static RtnInfo InvokeInBoundHandleError(String rtn_ext) {
        return new RtnInfo(RtnCodes.INBOUND_EXCEPTION, "fail to invoke handler", rtn_ext);
    }
    
    
    /**
     * 调用outboundhandler异常
     */
    public static RtnInfo InvokeOutBoundHandleError(String rtn_ext) {
        return new RtnInfo(RtnCodes.OUTBOUND_EXCEPTION, "fail to invoke handler", rtn_ext);
    }
 

}

